package com.example.member.modules.member.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.common.log.annotation.MemberLog;
import com.example.common.security.component.CustomUser;
import com.example.common.security.util.SecurityUtils;
import com.example.member.modules.member.entity.Member;
import com.example.member.modules.member.service.IMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.api.ApiController;

import java.math.BigDecimal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 章侠杰
 * @since 2018-12-07
 */
@RestController
@RequestMapping("/member")
@Api("会员信息")
public class MemberController extends ApiController {

    @Autowired
    private IMemberService memberService;

    @MemberLog("会员信息")
    @ApiOperation(value = "会员信息", notes = "获取会员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", paramType = "path", value = "会员用户名称", required = true, dataType = "String"),
    })
    @GetMapping("/info/{username}")
    public Member getMemberInfo(@PathVariable String username){
        return memberService.getOne(
                new QueryWrapper<Member>()
                .eq("username",username));
    }


    @MemberLog("当前会员信息")
    @ApiOperation(value = "当前会员信息", notes = "获取当前会员信息")
    @GetMapping("/cur-member")
    public Member getCurMember(){
        CustomUser user = SecurityUtils.getUser();
        return memberService.getOne(
                new QueryWrapper<Member>()
                        .eq("username",user.getUsername()));
    }

}
